import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class GUIPatient extends JPanel {

		private JLabel welcome;
		private JPanel center;
		private JPanel panel;
		private JTextField sugar;
		private JTextField pressure;
		private JTextField weight;
                private JTextField day;
                private JTextField month;
                private JTextField year;
		private JButton update;
		private Patient current;
		
		private JTabbedPane jPane;
		
		public GUIPatient(Patient p)
		{

			current = p;

			welcome = new JLabel("Enter your Health updates below");
			sugar = new JTextField("Blood Sugar");
			pressure = new JTextField("Blood Pressure");
			weight = new JTextField("Weight");
                        day = new JTextField("Day");
                        month = new JTextField("Month");
                        year = new JTextField("Year");
			update = new JButton("Update information");
			center = new JPanel();
			center.setLayout(new BoxLayout(center, BoxLayout.Y_AXIS));
			center.add(sugar);
			center.add(pressure);
			center.add(weight);
                        center.add(day);
                        center.add(month);
                        center.add(year);
			panel = new JPanel();
			panel.setLayout(new BorderLayout());
			panel.add(welcome, BorderLayout.NORTH);
			panel.add(center, BorderLayout.CENTER);
			panel.add(update, BorderLayout.SOUTH);
			
			this.add(panel);
			
			UpdateListener listener = new UpdateListener();
			update.addActionListener(listener);
		}
		
		private class UpdateListener implements ActionListener
		{
			public void actionPerformed(ActionEvent event)
			{
				String s = sugar.getText();
                                String p= pressure.getText();
                                String w= weight.getText();
                                String d= day.getText();
                                String m= month.getText();
                                String y= year.getText();
				
                                boolean exceptionoccurred = false;
                                
                                try
                                {
                                double sug= Double.parseDouble(s);
                                double pres = Double.parseDouble(p);
                                double weig = Double.parseDouble(w);
                                int da = Integer.parseInt(d);
                                int mon = Integer.parseInt(m);
                                int ye = Integer.parseInt(y);
                                
                                }
                                catch(Exception ex)
                                {
                                    exceptionoccurred = true;
                                    welcome.setText("Some information is incorrect.");
                                }
                                
                                if(!exceptionoccurred)
                                {
                                    current.addUpdate(s,p,w,d,m,y);   
                                    welcome.setText("Information updated!");
                                }
			}
		}	
	}